package main

import (
	"muziai-server/core"
	"muziai-server/flags"
	"muziai-server/global"
	"muziai-server/routers"
	"muziai-server/service/wx"
	"muziai-server/service/wx/auth"
	"muziai-server/service/wx/handle"
	"muziai-server/service/wx/login"
)

func main() {
	//global.DB = core.InitGorm()
	flags.Parse()
	global.Config = core.InitYaml()
	core.InitLogrus()
	core.InitIpSearcher()
	global.DB = core.InitGorm()
	global.Redis = core.InitRedisServer()

	if flags.Run() {
		return
	}
	//初始化路由
	go routers.InitRouters()
	//启动项目强制刷新一次token，存储到全局变量中
	type Wxservice struct {
		WxAuthService   auth.WxAuthService
		WxHandleService handle.WxHandleService
		WxLoginService  login.WxLoginService
	}
	type WxApi struct {
		WxService wx.Wxservice
	}
	//实例化微信服务
	wxservice := wx.Wxservice{}
	wxservice.WxAuthService.GetAccessToken(global.Config.WxLogin.Appid, global.Config.WxLogin.Secret, false)
	//开启定时服务，1.55h刷新一次全局变量,保证不过期
	wxservice.WxAuthService.StartAccessTokenScheduler(global.Config.WxLogin.Appid, global.Config.WxLogin.Secret)

}
